<%@ page pageEncoding="UTF-8"%>
<%@ taglib prefix="form" uri="http://www.springframework.org/tags/form"%>
<%@ taglib prefix="isperp" uri="/WEB-INF/tlds/isperp.tld"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>

<isperp:individuationView>
	<jsp:body>
<div>
	<form:form commandName="model" cssClass="validate"
		id="individuationForm" action="individuation/individuation/save">
		<form:hidden path="id" />
		<form:hidden path="approverId" />
		<form:hidden path="processName" />
		<form:hidden path="processKey" />
		<form:hidden path="categoryId" />
		<div id="createCusUserDialog" title="创建用户"
			style="display:none;padding:5px;-webkit-overflow-scrolling:touch; overflow:auto;">
			<iframe id="createCusUserIframe" src=""
				style="width:100%;height:100%;;border:none"></iframe>
		</div>
		<table class="form-table">
			<tr>
				<td colspan="4">
					<div class="header" style="padding:1px;">
						<h3>基本信息</h3>
					</div></td>
			</tr>

			<tr>
				<td class="td1">请求人：</td>
				<td class="td2"><input type="hidden" id="cusUserId"
					name="cusUserId" value="${model.cusUserId }"><input
					id=txtCusUserName name="cusUserName" class="hidden" type="text"
					maxlength="200" style="width:250px"> <isperp:listSelector
						autocomplete="true" id="cusUserIdSelector"
						afterSelectEmpty="clearCusUser();" displayColumn="fullname"
						autocompleteUrl="customer/user/list"
						afterSelected="setCusUser(ids)" valueColumn="id"
						valueControlId="cusUserId" displayValueCssClass="required"
						url="customer/user/list">
						<isperp:column name="id" title="id" hidden="true"></isperp:column>
						<isperp:column name="fullname" title="名称" width="90">
						</isperp:column>
						<isperp:column name="email" title="邮件" width="110">
						</isperp:column>
						<isperp:column name="tel" title="电话" width="90">
						</isperp:column>
						<isperp:column name="mobile" title="手机" width="90">
						</isperp:column>
						<isperp:column name="customerName" title="所属客户" width="110">
						</isperp:column>
					</isperp:listSelector> <a class="nui-txt-link" href="javascript:openCreateCusUser(1);">
						创建用户 </a><a class="nui-txt-link"
					href="javascript:openCreateCusUser(0);">更新用户信息
						</button>
				</td>
			</tr>
			<tr id="trUserInfo">
				<td class="td1"></td>
				<td class="td2" style="height:24px"><input
					id="hidCusUserCustomerId" type="hidden">电话：<label
					id="lbCusUserTel"></label>&nbsp;类型：<label id="lbCusUserType"></label>&nbsp;邮箱：<label
					id="lbCusUserEmail"></label>&nbsp;所在部门：<label
					id="lbCusUserDepartment"></label>&nbsp;联系地址：<label
					id="lbCusUserLinkaddress"></label></td>
			</tr>
			<tr>
				<td class="td1">选择项目：</td>
				<td class="td2"><form:select path="projectId"
						data-width="250px" items="${projects }" itemLabel="name"
						itemValue="id" cssClass="search required"></form:select></td>
			<tr>
			<tr>

				<td class="td1">描述：</td>
				<td class="td2" colspan="3"><textarea id="incidentDescription"
						class="required" style="height:60px;width:80%;" name="description">${model.description }</textarea>
				</td>
			</tr>
			<tr>
				<td class="td1">附件：</td>
				<td class="td2"><isperp:uploader sourceId="${model.id }"
						id="incidentFiles"></isperp:uploader>
				</td>
			</tr>

		</table>
		<div style="position: relative;">
			<jsp:include page="../../incident/incident/incidentProperty.jsp"></jsp:include>
		</div>
		
	</form:form>
	 <div>
			<div class="header" style="padding:1px;min-height: 80px;">
				<h3>
					跟踪消息(<span style="color:red;" id="appMessageRemindCount1">0</span>)&nbsp;&nbsp;<input type="button" class="button" value="添加" 
					onclick="isperp.openDialog({title:'跟踪消息',windowSize:'small',contentUrl:'app/message/remind/msgRemindEdit?type=task&sourceId=${model.id }&pcontrolid=appMessageRemindGrid1'})">
				</h3>
				<isperp:grid
				url="app/message/remind/listBySourceId?sourceId=${model.id }"
				showSearchbar="false" gridId="appMessageRemindGrid1"
				cusDialogSize="normal" showToolbar="false" rownumbers="false"
				height="auto" cusFormatterActions="false"
				loadComplete=" $('#appMessageRemindCount').text( appMessageRemindGrid1.jqGrid.getGridParam('records'));$('#appMessageRemindCount1').text( appMessageRemindGrid1.jqGrid.getGridParam('records'));">
				<jsp:attribute name="toolbar">
						<isperp:button id="appMessageRemindCreate" icon="icon-plus" 
						text="添加" cssClass="button" 
						onclick="isperp.openDialog({title:'跟踪消息',windowSize:'small',contentUrl:'app/message/remind/msgRemindEdit?type=task&sourceId=${model.id }&pcontrolid=appMessageRemindGrid1'})"></isperp:button>
					</jsp:attribute>
					<jsp:body>
				<isperp:column name="id" title="id" hidden="true"></isperp:column>
				<isperp:column name="content" title="跟踪内容" isFormatterFun="true"
						formatter="return formatAppMessageContent(rowObject);"></isperp:column>
				<isperp:column name="modifyDate" title="处理时间" hidden="true">
				</isperp:column>
				<isperp:column name="creatorName" title="创建者" hidden="true">
				</isperp:column>
				</jsp:body>
			</isperp:grid>
			</div>
			
			

		</div>
	<div id="dialogChangeUserInfo" title="选择处理人" style="display: none;">
		<table class="search-table" style="width:420px;margin:10px 5px">
			<tr>
				<td style="padding:8px">

					<div class="row">
						<div id="cbNextHandPersonList"></div>
					</div>
				</td>
			</tr>
			<tr>
				<td style="padding:8px">
					<div class="row no-bg">
						<p class="_100">
							<label for="" style="font-weight: bold;">处理意见</label>
							<textarea id="backOpnion" name="backOpnion" rows="6"
								style="width:96%" class=""></textarea>
						</p>
					</div>
				</td>
			</tr>

		</table>
	</div>
	<isperp:buttonList>
		<!-- <input type="button" value="提交" class="button" id="sbBtn"
			onclick="openChoseNextStepUserWindow()"> -->
		<isperp:processButtons processKey="${processKey }"
			areHideProcessBtn="false"
			beforeSubmit="function c(){return beforeSubmit();}"
			processId="${model.processId }" businessKey="${model.id }"
			formId="individuationForm"></isperp:processButtons>
	</isperp:buttonList>
</div>

	</jsp:body>
</isperp:individuationView>
<script type="text/javascript">
	var createCusUserDlg = $("#createCusUserDialog").dialog({
		modal : true,
		autoOpen : false,
		width : 500,
		height : 500,
		open : function(event, ui) {
			$("#createCusUserId").val("");

		},
		buttons : {
			保存 : function() {
				var $me = $(this);
				isperp.getWindow("createCusUserIframe").sumbitCusUserForm(function(id) {
					$me.dialog("close");
					$("#cusUserId").val(id);
					setCusUser(id);
				});

			}

		}
	});
	//新增用户
	function openCreateCusUser(isNew) {
		var title;
		if (isNew) {
			title = "创建用户";
			$("#createCusUserIframe").attr("src", "customer/user/createUserEdit");
		} else {
			title = "更新用户信息";
			var userId = $("#cusUserId").val();
			$("#createCusUserIframe").attr("src", "customer/user/createUserEdit?id=" + userId);
		}

		createCusUserDlg.dialog({
			title : title
		});
		createCusUserDlg.dialog("open");

	}
	//显示用户详细资料，并带出用户关联的项目信息以及其关联的所有资产
	var setCusUser = function(userId) {
		userId = userId || "${model.cusUserId}";
		if (userId) {
			$.getJSON("customer/user/getDetail?id=" + userId + "&icdId=", function(data) {
				if (data) {
					$("#trUserInfo").show();
					$("#cusUserId").val(data.id);
					$("#txtCusUserName").val(data.fullname);

					$("#cusUserIdSelector").val(data.fullname);

					//$("#lbCusUserCustomer").html(data.customer_name);
					var tm = "";
					if (data.mobile)
						tm += data.mobile
					if (data.tel)
						tm += "/" + data.tel;

					$("#lbCusUserTel").html(tm);

					if (data.email != undefined)
						$("#lbCusUserEmail").html(data.email);
					else
						$("#lbCusUserEmail").html("");
					if (data.department_treenode_name_path != undefined)
						$("#lbCusUserDepartment").html(data.department_treenode_name_path);
					else
						$("#lbCusUserDepartment").html("");
					if (data.address != undefined)
						$("#lbCusUserLinkaddress").html(data.address);
					else
						$("#lbCusUserLinkaddress").html("");
				}
				//ciUseRelationGrid.reload();
			});
		}
	};
	function clearCusUser() {
		$("#cusUserId").val("");
		$("#txtCusUserName").val("");
		$("#cusUserIdSelector").val("");
		$("#lbCusUserTel").html("");
		//$("#lbCusUserCustomer").html("");
		$("#hidCusUserCustomerId").val("");
		$("#lbCusUserType").html("");
		$("#lbCusUserEmail").html("");
		$("#lbCusUserDepartment").html("");
		$("#lbCusUserLinkaddress").html("");
		$("#lbCusIdCard").html("");
		$("#lbCusBankCardNumber").html("");
	}
</script>

<script type="text/javascript">
	function openChoseNextStepUserWindow() {
		result = $("#individuationForm").valid();
		if (!result)
			return false;
		var categoryId = $("#categoryId").val();
		isperp.openDialog({
			id : "nextStepUserDialog",
			onThisWindow : true,
			contentUrl : 'workflow/processRun/beginSubEdit?categoryId=' + categoryId,
			title : "选择处理人",
			width : 600,
			height : 520,
			buttons : [ {
				text : "提交",
				"class" : 'nui-mainbtn',
				click : function() {
					var winObj = $("#nextStepUserDialog").find("iframe")[0].contentWindow;
					var userName = winObj.getSelectedValue();
					var suggestion = winObj.document.getElementById("suggestion").value;

					if (userName == "" || userName == undefined) {
						isperp.alert("请选择下一步处理人！");
						return false;
					} else {
						$("#approverId").val(userName);
					}
					$(this).wijdialog("close");
					$("#sbBtn").hide();
					$("[data-name='提交']").attr("data-suggestion", suggestion);
					$("[data-name='提交']").click();
					//$(this).wijdialog("close");
				}
			}, {
				text : "关闭",
				"class" : 'grey',
				click : function() {
					$(this).wijdialog("close");
				}
			} ]
		});
		return false;
	}

	function cNextHandler(obj) {
		var ifChecked = obj.checked;
		var v = $(obj).val();
		var curUsers = $("#approverId").val();
		if (ifChecked && curUsers.indexOf(v) < 0) {
			if (curUsers == "") {
				curUsers += v;
			} else {
				curUsers += "," + v;
			}

		} else if (!ifChecked && curUsers.indexOf(v) > -1) {
			curUsers = curUsers + ",";
			curUsers = curUsers.replace((v + ","), "");
			curUsers = curUsers.substring(0, curUsers.length - 1);
		}
		$("#approverId").val(curUsers);

	}

	$("#dialogChangeUserInfo").dialog({
		autoOpen : false,
		resizable : false,
		modal : true,
		width : 440,
		buttons : [ {
			text : "提交",
			"class" : "nui-mainbtn",
			click : function() {
				if ($("#approverId").val() == "") {
					isperp.alert("请选择下一步处理人！");
					return false;
				}
				$(this).dialog("close");
				$("#sbBtn").hide();
				var suggestion = $("#backOpnion").val();
				$("[data-name='提交']").attr("data-suggestion", suggestion);
				$("[data-name='提交']").click();
			}
		}, {
			text : "关闭",
			click : function() {

			}

		} ]
	});

	var $wizCreate = isperp.wizard({
		wizardId : "createWizard"
	});
	var createWizard_Event1 = function(index, obj) {
		var result = $("#individuationForm").valid();
		var icdCategory = $("#icdCategorySelector").val();
		var title = $("#incidentTitle").val();
		var description = $("#incidentDescription").val();
		var area = $("#area").val();
		if (icdCategory == "" || title == "" || description == "" || area == "") {
			return false;
		} else {
			$("[class='error inline']").remove();
			return true;
		}
	};

	var createWizard_Event2 = function(index, obj) {
		var result = $("#individuationForm").valid();
		if (!result) {
			return false;
		}
		if ($("#serviceCategoryId").val() == "") {
			isperp.alert("请选择技术服务目录！");
			return false;
		}

	};
	function formatSrcName(rowObject) {
		return "<a href=\"javascript:isperp.openDialog({contentUrl:'serviceCatalog/service/view?id=" + rowObject.id + "'});\">" + rowObject.name + "</a>";
	}

	var srcServiceGridSelected = function(id, name) {

		if (!id && !name) {
			var selectedRow = srcServiceGrid.getRowData();
			id = selectedRow.id;
			name = selectedRow.name;
		}

		if (id && name) {

			var msg = name + "  <a class='nui-txt-link' href='javascript:void(0)' style='padding-left:5px' onclick='reselectService();'>[修改]</a>";

			$("#selectSrcServiceGrid").hide();
			$("#serviceCategoryId").val(id);
			$("#serviceCategoryMsg").html(msg);
			$("#icdIncidentServiceCatalog").html(name);
		}
	};

	function setServiceCatalogValue(id, name) {

		srcServiceGridSelected(id, name);
		$("#projectServiceDialog").wijdialog("close");
	}

	var reselectService = function() {
		$("#selectSrcServiceGrid").show();
		$("#serviceCategoryMsg").html("");
		$("#serviceCategoryId").val("");
		$("#icdIncidentServiceCatalog").html("");
	};

	function projectServiceCategory_Onclick() {
		isperp.openDialog({
			id : "projectServiceDialog",
			onThisWindow : true,
			title : "选择服务目录",
			windowSize : "normal",
			contentUrl : "serviceCatalog/service/selectEdit?projectId=" + $("#incidentProjectId").val(),
			buttons : [ {
				text : "确定",
				"class" : "nui-mainbtn",
				click : function() {
					var $me = $(this);
					$me.find("iframe")[0].contentWindow.getSelectRow();
				}
			}, {
				text : "关闭",
				"class" : 'grey',
				click : function() {
					$(this).wijdialog("close");
				}
			} ]
		});

	}
</script>

<script type="text/javascript">
	function beforeSubmit() {
		//保存扩展属性
		//saveProperty();
		return true;
	}

	//事件标题变化时，自动匹配服务目录
	$("#incidentTitle,#incidentProjectId").change(function() {

		var title = $("#incidentTitle").val();
		var projectId = $("#incidentProjectId").val();

		//searchHelpInfo(projectId, title);
	});

	var reselectService = function() {

		$("#selectSrcServiceGrid").show();
		$("#serviceCategoryMsg").html("");
		$("#serviceCategoryId").val("");
		$("#icdIncidentServiceCatalog").html("");
	};

	var assetSelected = function() {

		var selectedRow = assAssectGrid.getRowData();
		if (selectedRow && selectedRow.name) {

			var htmlname = "<a href=\"javascript:isperp.openDialog({contentUrl:'configuration/ci/edit?id=" + selectedRow.id + "'});\">" + selectedRow.name + "</a>";

			var msg = htmlname + "  <a href='javascript:void(0)' style='color:blue;padding-left:5px' onclick='reselectAsset();'>[修改]</a>";

			$("#selectAssectGridGrid").hide();
			$("#assAssetId").val(selectedRow.id);
			$("#ciIdMsg").html(msg);

			$("#icdIncidentAssets").html(selectedRow.name);
		}
	};

	var reselectAsset = function() {

		$("#selectAssectGridGrid").show();
		$("#ciIdMsg").html("");
		$("#assAssetId").val("");
		$("#icdIncidentAssets").html("");

	};
	function submitIncident(status) {

		if ($("#serviceCategoryId").val() == "") {
			isperp.alert("请选择服务目录！");
			return false;
		}
		isperp.showLoading({
			onThisWindow : true
		});
		$("#individuationForm").attr("action", "incident/incident/saveAndStart");
		var res = isperp.submitForm({
			formId : "individuationForm",
			data : {
				"type" : status
			},
			success : function(responseText) {
				self.location = responseText.data + "?id=${model.id}";
			}
		});
		if (!res) {
			isperp.hideLoading({
				onThisWindow : true
			});
		}
	}

	//改变处理方式
	//改变处理方式
	function changesway(v) {

		if (v == "1") {
			$("#subway_dealdiv").show();
			$("#subway_dealdiv").find("input").attr("disabled", false);
			$("#subway_dealdiv").find("select").attr("disabled", false);
			$("#subway_dealdiv").find("textarea").attr("disabled", false);
			$("#subway_dealdiv").find("select").trigger("chosen:updated");

			$("#supporter_tr2line").hide();
			$("#supporter_tr2line").find("input").attr("disabled", 'disabled');
			$("#projectMemberGrid_div").hide();

			$("#reject_tr").hide();
			$("#reject_tr").find("textarea").attr('disabled', 'disabled');

		} else if (v == "2") {
			$("#subway_dealdiv").hide();
			$("#subway_dealdiv").find("input").attr('disabled', 'disabled');
			$("#subway_dealdiv").find("select").attr('disabled', 'disabled');
			$("#subway_dealdiv").find("textarea").attr('disabled', 'disabled');
			$("#projectMemberGrid_div").show();

			$("#supporter_tr2line").show();
			$("#supporter_tr2line").find("input").attr("disabled", false);

			$("#reject_tr").hide();
			$("#reject_tr").find("textarea").attr('disabled', 'disabled');

		} else {
			$("#subway_dealdiv").hide();
			$("#subway_dealdiv").find("input").attr("disabled", false);
			$("#subway_dealdiv").find("select").attr("disabled", false);
			$("#subway_dealdiv").find("textarea").attr("disabled", false);

			$("#projectMemberGrid_div").hide();

			$("#supporter_tr2line").hide();
			$("#supporter_tr2line").find("input").attr("disabled", false);
			$("#reject_tr").show();
			$("#reject_tr").find("textarea").attr('disabled', false);

		}
	}

	$(document).ready(function() {
		var modelEdit = "${modelEdit}";
		setCusUser();
	});

	function changeIcdCategory(ids, names, treeNode) {

		//searchCategoryMember(treeNode.id);
		//searchCategoryDandang(treeNode.id);
		//改变时间描述的提示内容
		var tipsStr = "";
		switch (names) {
		case "软件定制开发流程":
			tipsStr = "1、现有系统界面，要修改的功能的截图（用红色标注出要修改的内容）。  2、	新增的功能，注明新增的功能名称，提供设计图（用红色标注出要修改的内容）；无法提供图片的，请按以下要求提供详细需求描述：  1)要做的功能名称。  2)要做的功能目标、范围。  3)要实现的功能流程框图。  4)要实现的功能流程说明。  3、	接口对接提供接口附件。4、标注程序获取期望时间，默认为回复单中“开发周期”或“项目起止日期”。";
			break;
		case "技术支持流程":
			tipsStr = "请注明如有定制开发，必须标注定制开发单号；315/415/515POS修改或申领程序，必须提供院校代码";
			break;
		default:
			break;
		}
		$("#description").attr("placeholder", tipsStr);
		setCategoryProperty(ids, names, treeNode);
	}
</script>